const formatTime = date => {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();
  return [year, month, day].map(formatNumber).join('/') + '_' + [hour, minute, second].map(formatNumber).join(':');
};

function getTotalSeconds(hh, mm, ss) {
  return hh * 3600 + mm * 60 + ss * 1;
}

function getHHSSMM(totalInSecond) {
  var hh = parseInt(totalInSecond / 3600);
  if (hh < 10) hh = '0' + hh;
  var mm = parseInt(totalInSecond / 60 % 60);
  if (mm < 10) mm = '0' + mm;
  var ss = parseInt(totalInSecond % 60 % 60);
  if (ss < 10) ss = '0' + ss;
  return `${mm}:${ss}`;
}

let generateTimeArr = range => {
  //range should be the max value -1
  let retArr = [];

  for (let i = 0; i < range; i++) {
    retArr[i] = i;
  }

  return retArr;
};

const formatNumber = n => {
  n = n.toString();
  return n[1] ? n : '0' + n;
};
const getDay=(day=0)=>{
 
  　　var today = new Date();
   
   
   
  　　var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
   
   
   
  　　today.setTime(targetday_milliseconds); //注意，这行是关键代码
   
   
   
  　　var tYear = today.getFullYear();
   
  　　var tMonth = today.getMonth();
   
  　　var tDate = today.getDate();
   
  　　tMonth = tMonth + 1;
      if(tMonth.toString().length == 1){
        　　　　tMonth = "0" + tMonth;
    　　}
    if(tDate.toString().length == 1){
   
      　　　　　tDate = "0" + 　tDate;
   
  　　}
  　
   
  　　return tYear+"-"+tMonth+"-"+tDate;
   
  };

module.exports = {
  formatTime: formatTime,
  getTotalSeconds: getTotalSeconds,
  getHHSSMM: getHHSSMM,
  generateTimeArr: generateTimeArr,
  getDay:getDay
};